<?php

    namespace yaliSDK\common;

    use yaliSDK\message\Code;
    use yaliSDK\message\ExceptionFactory;
    use yaliSDK\message\IMessage;

    class Result extends Entity {
        private $data;
        private $msg;
        private $code;

        public function __construct($data = null, int $code = null, string $msg = '' ) {

            $this->data = $data;
            $this->code = $code ?? Code::$SUCCESS;
            $this->msg = $msg;

        }

        /**
         * @param null $data
         */
        public function setData($data) {
            $this->data = $data;
        }
        public function getData() {
            return $this->data;
        }

        public function getCode() {
            return $this->code;
        }

        public function getMsg() {
            return $this->msg;
        }

        public function toJson($options = JSON_UNESCAPED_UNICODE) {
            return $this->__toJson(get_object_vars($this), $options);
        }

        static public function _getInstanceData($instance=null) {
                if ($instance instanceof Result) {
                    return $instance->getData();
                }
                return null;
        }
    }